package com.bestv.engine.filter;

import com.bestv.engine.model.RecommendationItem;
import org.apache.commons.lang3.StringUtils;

import java.util.HashSet;
import java.util.Set;

/**
 * Created by Henry on 14-6-17.
 */
public class MediaCodeFilter implements Filter {
    private Set<String> itemIdSet;

    public MediaCodeFilter(String[] itemIds) {
        itemIdSet = new HashSet<String>();
        if (itemIds == null) return;
        for (String itemId : itemIds) {
            if (StringUtils.isBlank(itemId) || itemIdSet.contains(itemId))
                continue;
            itemIdSet.add(itemId);
        }
    }

    @Override
    public boolean accept(RecommendationItem item) {
        if (itemIdSet.contains(item.getItemId()))
            return false;
        itemIdSet.add(item.getItemId());
        return true;
    }
}
